package com.yiyahui.project.erp.controller;

import java.util.Date;
import java.util.List;

import com.yiyahui.common.utils.DateUtils;
import com.yiyahui.common.utils.poi.ExcelUtil;
import com.yiyahui.framework.aspectj.lang.annotation.Log;
import com.yiyahui.framework.aspectj.lang.enums.BusinessType;
import com.yiyahui.framework.web.controller.BaseController;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.framework.web.page.TableDataInfo;
import com.yiyahui.project.erp.domain.YiyaDailyBrowserInfo;
import com.yiyahui.project.erp.domain.YiyaOperationLog;
import com.yiyahui.project.erp.service.IYiyaOperationLogService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api("操作日志")
@RestController
@RequestMapping("/erp/operlogs")
public class YiyaOperationLogController extends BaseController {

    @Autowired
    private IYiyaOperationLogService yiyaOperationLogService;
    /*******************************每日浏览相关接口 *****************************************/
    /**
     * 查询每日浏览列表
     */
    @ApiOperation("查询每日浏览列表")
    @GetMapping("/dailybrowser/list")
    public TableDataInfo list(int type,Date date,int pageNum,int pageSize)
    {
        if(date == null)
            date = DateUtils.getNowDate();
        List<YiyaDailyBrowserInfo> dailybrowserlist = yiyaOperationLogService.getDailyBrowserList(type,date,(pageNum-1)*pageSize,pageNum*pageSize-1);
        return getDataTable(dailybrowserlist);
    }

    /**
     * 插入每日浏览记录
     */
    @ApiOperation("插入每日浏览记录")
    @PostMapping("/dailybrowser")
    public AjaxResult add(int type,Long userid)
    {
        int res = yiyaOperationLogService.insertDailyBrowserLog(type,userid);
        return toAjax(res);
    }

    /**
     * 删除某条每日浏览日志
     */
    @ApiOperation("删除几条每日浏览日志")
    @DeleteMapping("/dailybrowser/{keys}")
    public AjaxResult remove(@PathVariable String[] keys)
    {
        int res = yiyaOperationLogService.deleteDailyBrowserLog(keys);
        return toAjax(res);
    }

    /*******************************普通操作日志接口 *****************************************/
    /**
     * 查询操作日志列表
     */
    @ApiOperation("查询操作日志列表")
    @GetMapping("/useropera/list")
    public TableDataInfo list(YiyaOperationLog yiyaOperationLog)
    {
        startPage();
        List<YiyaOperationLog> list = yiyaOperationLogService.selectYiyaOperationLogList(yiyaOperationLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志列表
     */
    @ApiOperation("导出操作日志列表")
    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @GetMapping("/useropera/export")
    public AjaxResult export(YiyaOperationLog yiyaOperationLog)
    {
        List<YiyaOperationLog> list = yiyaOperationLogService.selectYiyaOperationLogList(yiyaOperationLog);
        ExcelUtil<YiyaOperationLog> util = new ExcelUtil<YiyaOperationLog>(YiyaOperationLog.class);
        return util.exportExcel(list, "operationlog");
    }

    /**
     * 获取操作日志详细信息
     */
    @ApiOperation("获取操作日志详细信息")
    @ApiImplicitParam(name = "id", value = "自增ID", required = true, dataType = "Long", paramType = "path")
    @GetMapping(value = "/useropera/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yiyaOperationLogService.selectYiyaOperationLogById(id));
    }

    /**
     * 新增操作日志
     */
    @ApiOperation("新增操作日志")
    @ApiImplicitParam(name = "yiyaOperationLog", value = "${tableComment}", dataType = "YiyaOperationLog")
    @Log(title = "操作日志", businessType = BusinessType.INSERT)
    @PostMapping(value = "/useropera")
    public AjaxResult add(@RequestBody YiyaOperationLog yiyaOperationLog)
    {
        return toAjax(yiyaOperationLogService.insertYiyaOperationLog(yiyaOperationLog));
    }

    /**
     * 修改操作日志
     */
    @ApiOperation("修改操作日志")
    @ApiImplicitParam(name = "yiyaOperationLog", value = "${tableComment}", dataType = "YiyaOperationLog")
    @Log(title = "操作日志", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/useropera")
    public AjaxResult edit(@RequestBody YiyaOperationLog yiyaOperationLog)
    {
        return toAjax(yiyaOperationLogService.updateYiyaOperationLog(yiyaOperationLog));
    }

    /**
     * 删除操作日志
     */
    @ApiOperation("删除操作日志")
    @ApiImplicitParam(name = "ids", value = "自增ID数组", required = true, dataType = "Long[]", paramType = "path")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/useropera/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yiyaOperationLogService.deleteYiyaOperationLogByIds(ids));
    }
}